@echo off

set SubFolder=%1
set ToolPath=%CD%
set LocalResPath=%ToolPath%\..\build\jsb-default
set RemoteResPath=%ToolPath%\RemoteRes

cd %ToolPath%
git pull
if %errorlevel%==0 (
    goto :domain
) else (
    pause
    goto :mainend
)

:domain
for /f "delims=" %%a in (version.txt) do (
	set version=%%a
)
for /f "tokens=1-4 delims=." %%a in ("%version%") do (
	set Version1=%%a
	set Version2=%%b
	set Version3=%%c
	set /a Version4=%%d+1
)
set addversion=%Version1%.%Version2%.%Version3%.%Version4%
node version_generator.js -u %SubFolder% -v %addversion% -s %LocalResPath% -d %LocalResPath%
if exist %LocalResPath%\version.manifest (
    echo %addversion%
    echo %addversion%>version.txt
) else (
    echo failed
)

cd %LocalResPath%\assets
for /f "delims=" %%i in ('dir /b /a-d /s "*.manifest"') do (
    echo f|xcopy %LocalResPath%\project.manifest %%i /y
)

cd %ToolPath%
md %ToolPath%\RemoteRes
cd %RemoteResPath%
rd %RemoteResPath%\%SubFolder%\assets /s /q
rd %RemoteResPath%\%SubFolder%\src /s /q
md %RemoteResPath%\%SubFolder%\assets
md %RemoteResPath%\%SubFolder%\src
echo d|xcopy %LocalResPath%\assets %RemoteResPath%\%SubFolder%\assets /s/e/y
echo d|xcopy %LocalResPath%\src %RemoteResPath%\%SubFolder%\src /s/e/y
echo f|xcopy %LocalResPath%\project.manifest %RemoteResPath%\%SubFolder%\project.manifest /s/e/y
echo f|xcopy %LocalResPath%\version.manifest %RemoteResPath%\%SubFolder%\version.manifest /s/e/y

cd %ToolPath%
git add version.txt
git commit -m "Update Version"
git push

:mainend

exit